package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoInsertFill;
import com.sky.annotation.AutoUpdatetFill;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;
import java.util.List;

/**
 * The interface Set meal mapper.
 */
@Mapper
public interface SetmealMapper {


    /**
     * 根据分类id查询套餐数量
     *
     * @param categoryId the category id
     * @return the long
     */
    @Select("select count(*) from setmeal where category_id = #{categoryId}")
    Long selectCountByCategoryId(@Param("categoryId") Long categoryId);


    /**
     * 更据条件查询数量
     *
     * @param setmealDTO the setmeal dto
     * @return the integer
     */
    Integer selectCount(SetmealDTO setmealDTO);


    /**
     * 新增套餐
     *
     * @param setmeal the setmeal
     */
    @AutoInsertFill
    void insert(Setmeal setmeal);


    /**
     * 菜品分页查询
     *
     * @param setmealPageQueryDTO the setmeal page query dto
     * @return the page
     */
    Page<SetmealVO> selectList(SetmealPageQueryDTO setmealPageQueryDTO);


    /**
     * 根据ids删除
     *
     * @param ids the ids
     */
    void deleteByIds(List<Long> ids);


    /**
     * 套餐起售、停售
     *
     * @param status the status
     * @param ids    the ids
     */
    void updateStatus(Integer status, List<Long> ids);


    /**
     * 根据id和状态得到数量
     *
     * @param ids    the ids
     * @param status the status
     * @return the integer
     */
    Integer selectCountByStatus(List<Long> ids, Integer status);


    /**
     * Select by id setmeal vo.
     *
     * @param id the id
     * @return the setmeal vo
     */
    @Select("select id, category_id, name, price, status, description, image,  update_time,  update_user from setmeal where id = #{id}")
    SetmealVO selectById(Long id);


    /**
     *  根据id更新
     *
     * @param setmeal the setmeal
     */
    @AutoUpdatetFill
    void updateById(Setmeal setmeal);

    /**
     * 动态条件查询套餐
     * @param setmeal
     * @return
     */
    List<Setmeal> list(Setmeal setmeal);

    /**
     * 根据套餐id查询菜品选项
     * @param setmealId
     * @return
     */
    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);
}
